package com.xsr.aop;


import org.aopalliance.intercept.MethodInterceptor;
import org.aopalliance.intercept.MethodInvocation;

import org.springframework.cglib.proxy.MethodProxy;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

/**
 * @author 邢式瑞
 * @version 1.0
 * @project day37
 * @date 2022/9/6 11:42
 */
public class MyMethodInterceptor implements MethodInterceptor {


    @Override
    public Object invoke(MethodInvocation invocation) throws Throwable {
        System.out.println("事务控制");
        Object result =null;
        try {
            Method method = invocation.getMethod();
            method.invoke(invocation.getThis(),invocation.getArguments());
            System.out.println("一切顺利");
            return result;

        } catch (Exception e) {
            //e.printStackTrace();
            System.out.println("核心代码异常");
        }
        return result;
    }
}
